<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<meta name="layout" content="main" />
		<title>Edycja użytkownika</title>
	</head>
	<body>

		<div class="nav">
            <g:ifAllGranted role="ROLE_ADMIN">
                <span class="menuButton"><g:link class="list" action="list">Lista użytkowników</g:link></span>
                <span class="menuButton"><g:link class="create" action="create">Nowy użytkownik</g:link></span>
            </g:ifAllGranted>
		</div>

		<div class="body">
			<h1>Edycja użytkownika ${person}</h1>
			<g:if test="${flash.message}">
			<div class="message">${flash.message}</div>
			</g:if>
			<g:hasErrors bean="${person}">
			<div class="errors">
				<g:renderErrors bean="${person}" as="list" />
			</div>
			</g:hasErrors>

			<g:form method="post">
				<input type="hidden" name="id" value="${person?.id}" />
				<div class="dialog">
					<table>
					<tbody>

                        <tr class="prop">
							<td valign="top" class="name">
								<label for="firstName">Imię:</label>
							</td>
							<td valign="top" class="value ${hasErrors(bean:person,field:'firstName','errors')}">
								<input type="text" id="firstName" name="firstName" value="${person?.firstName?.encodeAsHTML()}"/>
							</td>
						</tr>

						<tr class="prop">
							<td valign="top" class="name">
								<label for="lastName">Nazwisko:</label>
							</td>
							<td valign="top" class="value ${hasErrors(bean:person,field:'lastName','errors')}">
								<input type="text" id="lastName" name="lastName" value="${person?.lastName?.encodeAsHTML()}"/>
							</td>
						</tr>

						<tr class="prop">
							<td valign="top" class="name">
								<label for="street">Ulica:</label>
							</td>
							<td valign="top" class="value ${hasErrors(bean:person,field:'street','errors')}">
								<input type="text" id="street" name="street" value="${person?.street?.encodeAsHTML()}"/>
							</td>
						</tr>

						<tr class="prop">
							<td valign="top" class="name">
								<label for="city">Miasto:</label>
							</td>
							<td valign="top" class="value ${hasErrors(bean:person,field:'city','errors')}">
								<input type="text" id="city" name="city" value="${person?.city?.encodeAsHTML()}"/>
							</td>
						</tr>

						<tr class="prop">
							<td valign="top" class="name">
								<label for="zipCode">Kod pocztowy:</label>
							</td>
							<td valign="top" class="value ${hasErrors(bean:person,field:'zipCode','errors')}">
								<input type="text" id="zipCode" name="zipCode" value="${person?.zipCode?.encodeAsHTML()}"/>
							</td>
						</tr>

						<tr class="prop">
							<td valign="top" class="name">
								<label for="passwd">Hasło:</label>
							</td>
							<td valign="top" class="value ${hasErrors(bean:person,field:'passwd','errors')}">
								<input type="password" id="passwd" name="passwd" value="${person?.passwd?.encodeAsHTML()}"/>
							</td>
						</tr>

                        <g:ifAllGranted role="ROLE_ADMIN">
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="enabled">Konto włączone:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:person,field:'enabled','errors')}">
                                    <g:checkBox name="enabled" value="${person?.enabled}"/>
                                </td>
                            </tr>
                        </g:ifAllGranted>

                        <g:ifAllGranted role="ROLE_ADMIN">
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="username">Login/Email:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:person,field:'username','errors')}">
                                    <input type="text" id="username" name="username" value="${person?.username?.encodeAsHTML()}"/>
                                </td>
                            </tr>
                        </g:ifAllGranted>

                        <g:ifAllGranted role="ROLE_ADMIN">
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="authorities">Role:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:person,field:'authorities','errors')}">
                                    <ul>

                                    <g:set var="list" value="[]"/>
                                    <g:each var="b" in="${authorityList.authority}">
                                    <g:each var="a" in="${person?.authorities?}">
                                    <g:if test="${b==~ a.authority}">
                                    <%if(!list.contains(b)){list.add(b);%>
                                        <li>${a.authority?.substring(5)?.toLowerCase()?.encodeAsHTML()}
                                            <g:checkBox name="${a.authority}" value="${true}"/>
                                        </li>
                                    <%}%>
                                    </g:if>
                                    </g:each>
                                    <%if(!list.contains(b)){list.add(b);%>
                                        <li>${b.substring(5)?.toLowerCase()?.encodeAsHTML()}
                                            <g:checkBox name="${b}" value="${false}"/>
                                        </li>
                                    <%}%>
                                    </g:each>
                                    </ul>
                                </td>
                            </tr>
                    </g:ifAllGranted>

					</tbody>
					</table>
				</div>

				<div class="buttons">
					<span class="button"><g:actionSubmit class="save" action="update" value="Aktualizuj" /></span>
                    <g:ifAllGranted role="ROLE_ADMIN">
                        <span class="button"><g:actionSubmit class="delete" onclick="return confirm('Are you sure?');" value="Usuń" /></span>
                    </g:ifAllGranted>
				</div>

			</g:form>

		</div>
	</body>
</html>

